package top.eggcode.component.office;

import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;

/**
 * Excel文档渲染工具
 */
public class ExcelRender {
    /**
     * 设置单元格内容，常规文本
     *
     * @param sheet       工作表格
     * @param addressCode 地址编号
     * @param content     内容
     */
    public void toCell(XSSFSheet sheet, String addressCode, String content) {
        CellAddress address = new CellAddress(addressCode);
        XSSFRow row = sheet.getRow(address.getRow());
        XSSFCell cell = row.getCell(address.getColumn());
        cell.setCellValue(content);
    }

    /**
     * 设置单元格内容，整型数值
     *
     * @param sheet       工作表
     * @param addressCode 地址编号
     * @param value       内容
     */
    public void toCellOfInt(XSSFSheet sheet, String addressCode, int value) {
        CellAddress address = new CellAddress(addressCode);
        XSSFRow row = sheet.getRow(address.getRow());
        XSSFCell cell = row.getCell(address.getColumn());
        cell.setCellValue(value);
    }
}
